#include "cm_nat/SearchDaemon.h"
#include "cm_nat/SearchClient.h"

using namespace cm_nat;

//daemon
int main()
{
    SocketReactor reactor;
    reactor.setTimeout(Poco::Timespan(1,0,0,0,0));

    ByteBufferPool bpool;
    bpool.setup(10, 200);

    Thread t;
    t.start(reactor);

    SearchDaemon sd( &bpool, &reactor );

    IPAddress ip("192.168.0.128");
    sd.setup(ip, "id", "pwd");

    std::string a;

    while(1){
        std::cin>>a;
        

    }


    return 0;
}

//client
int main2()
{
    SocketReactor reactor;
    reactor.setTimeout(Poco::Timespan(1,0,0,0,0));

    ByteBufferPool bpool;
    bpool.setup(10, 200);

    BaseTimer timer;
    timer.setup();

    Thread t;
    t.start(reactor);

    SearchClient sc( &bpool, &reactor, &timer );
    
    sc.setMediaAddress( SocketAddress("192.168.0.128", 6000) );

    IPAddress ip("192.168.0.128");
    sc.setup(ip);

    
    std::string a;

    while(1){
        std::cin>>a;
        //sc.search("id","pwd", SocketAddress("192.168.0.128", 6000) );
        if( a == "a")
            sc.search();

        if( a == "b" )
            sc.authenticate("id","pwd");
    }


    return 0;
}